//引入request 模块
var request = require('request');
function httpFormJson(url, form, method, cookie) {
    let header = getHeader(cookie);
    let option = {
        url: url,
        method: method,
        json: true,
        headers: header,
        form: form
    };
    return new Promise((resolve) => {
        request(option, function (error, response, body) {
            try {
                if (!error && response.statusCode === 200) {
                    resolve(response)
                } else {
                    resolve(error)
                }
            } catch (error) {
                resolve(response)
            }
        })
    })
};


function getHeader(cookie) {
    return {
        "Content-type": "application/x-www-form-urlencoded; charset=UTF-8",
        Cookie: cookie
    };
}
module.exports= {httpFormJson};